package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.Order;
import dao.OrderDao;
import dao.OrderUtil;

/**
 * Servlet implementation class DoViewOrder
 */
@WebServlet(
		name="DoViewOrder",
		urlPatterns= {"/servlet/DoViewOrder"},
		loadOnStartup = 1
		
		)
public class DoViewOrder extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoViewOrder() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		//response.setContentType("text/html,charset=utf-8");
		//request.setCharacterEncoding("utf-8");
		//String username=request.getParameter("username");
		//OrderDao orderDao=new OrderUtil();
		//Order order=orderDao.findByOrder_id(username);
		//HttpSession session=request.getSession();
		//session.setAttribute("order",order);
		//request.getRequestDispatcher("/ViewOrder.jsp").forward(request, response);
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String name=request.getParameter("username");
		OrderDao orderDao=new OrderUtil();
		Order order=orderDao.findByOrder_id(name);
		if(order!=null) {
			HttpSession session=request.getSession();
			session.setAttribute("order",order);
			request.getRequestDispatcher("/orderview.jsp").forward(request, response);
		}
		else {
			request.getRequestDispatcher("/null.jsp").forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
	}

}
